package com.geekaca.mvc.controller;

import com.geekaca.mvc.dao.UserMapper;
import com.geekaca.mvc.domain.User;
import com.geekaca.mvc.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/register")
    @ResponseBody
    public String register(@RequestBody User user) {

        System.out.println("list common(json)参数传递 user ==>" + user);
        Integer inserted = userService.register(user);
        if (inserted!=null && inserted>0){
            System.out.println("注册成功");
        }
        return "{'module':'list common for json param'}";
    }

    @RequestMapping("/getAllUser")
    @ResponseBody
    public String getAllUser() {

        int allUser = userService.getAllUser();
        System.out.println("alluser number :"  + allUser);

        return "{'number':'allUser'}";
    }
}

